<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org"  xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<meta charset="utf-8">
<head th:include="include :: header"></head>
<body class="gray-bg">
	<div class="wrapper wrapper-content ">
		<div class="row">
			<div class="col-sm-12">
				<div class="ibox float-e-margins">
					<div class="ibox-content">
						<form class="form-horizontal m-t" id="signupForm">
							<input type="hidden" th:value="${branchOffice.id}" id="id" name="id">
							<table class="table table-bordered table-condensed">
								<tbody>
								<tr>
									<th class="required" style="text-align: right;"><em class="gg-star">*</em>公司/个人:</th>
									<td><input id="name" name="name" class="form-control" th:value="${branchOffice.name}" type="text"/></td>
								</tr>
								<tr>
									<th class="required" style="text-align: right;"><em class="gg-star">*</em>联系人:</th>
									<td><input id="contacts" name="contacts" class="form-control" th:value="${branchOffice.contacts}" type="text"></td>
								</tr>

								<!--<tr>-->
									<!--<th class="required" style="text-align: right;"><em class="gg-star">*</em>手机号码:</th>-->
									<!--<td><input id="mobile" name="mobile" class="form-control" th:value="${branchOffice.mobile}" type="text"></td>-->
								<!--</tr>-->
								<tr>
									<th class="required" style="text-align: right;"><em class="gg-star">*</em>地区</th>
									<td colspan="3">
										<div id="ssq" class="gg-formDetail gg-font0" data-toggle="distpicker" th:attr="data-province=${branchOffice.province},data-city=${branchOffice.city},data-district=${branchOffice.area}">
											<div class="gg-area">
												<select class="form-control" id="province" name="province" th:value="${branchOffice.province}" onchange="getCity()"
														data-province="----选择省----">
												</select>
											</div>
											<div class="gg-area">
												<select class="form-control" id="city" name="city" data-city="----选择市----" th:value="${branchOffice.city}">
												</select>
											</div>
											<!--<div class="gg-area">-->
												<!--<select class="form-control" id="area" name="area"-->
														<!--data-district="&#45;&#45;&#45;&#45;选择区&#45;&#45;&#45;&#45;">-->
												<!--</select>-->
											<!--</div>-->
										</div>
									</td>
								</tr>
								<tr>
									<th class="required" style="text-align: right;"><em class="gg-star">*</em>详细地址:</th>
									<td colspan="3"><input id="address" name="address" class="form-control" th:value="${branchOffice.address}" type="text"/>
									</td>
								</tr>
								<tr>
									<th class="required" style="text-align: right;"><em class="gg-star">*</em>分润比例(%:</th>
									<td colspan="3"><input th:value="${branchOffice.profitRate}" id="profitRate" name="profitRate" class="form-control" type="number" placeholder="分润比例（百分比"/>
									</td>
								</tr>
								</tbody>
							</table>
							<div class="form-group text-center">
								<div class="col-sm-8 col-sm-offset-2">
									<button type="submit"  class="btn btn-primary"><i class="fa fa-check"></i>提交</button>
									<div class="btn btn-danger" onclick="closeDow()"><i class="fa fa-remove"></i> 关闭</div>
								</div>
							</div>
						</form>
					</div>
				</div>
			</div>
		</div>

	</div>
	<div th:include="include::footer"></div>
	<script type="text/javascript" src="/js/appjs/product/AreaData.js"></script>
	<script type="text/javascript" src="/js/appjs/branchOffice/manage/edit.js"></script>
	<script type="text/javascript">
		function closeDow() {
			var index = parent.layer.getFrameIndex(window.name); // 获取窗口索引
			parent.layer.close(index);
		}
		$(function () {
			//从js数据中获取地区
			$("#province").append("<option value=''>请选择省</option>");
			var selectProvince=$("#ssq").attr("data-province");
			for (var i = 0; i < provs_data.length; i++) {
				console.log(provs_data[i]);
				if(selectProvince==provs_data[i].text){
					$("#province").append("<option value='"+provs_data[i].text+"' data-code='"+provs_data[i].value+"' selected>"+provs_data[i].text+"</option>");
					var selectCity=$("#ssq").attr("data-city");
					getCity(selectCity);
				}else{
					$("#province").append("<option value='"+provs_data[i].text+"' data-code='"+provs_data[i].value+"' >"+provs_data[i].text+"</option>");
				}
			}
		});
		function getCity(selectCity){
			$("#city").empty();
			$("#city").append("<option value=''>请选择市</option>");
			//获取省级下的所有市
			var province_code=$("#province option:selected").attr("data-code");
			if (citys_data[province_code].length > 0) {
				var citys = citys_data[province_code];
				for (var j = 0; j < citys.length; j++) {
					if(selectCity==citys[j].text){
						$("#city").append("<option value='" + citys[j].text + "' data-code='" + citys[j].value + "' selected>" + citys[j].text + "</option>");
					}else {
						$("#city").append("<option value='" + citys[j].text + "' data-code='" + citys[j].value + "' >" + citys[j].text + "</option>");
					}
				}
			}
		}
		function clearSelects(){
			$('.city').attr('checked',false).removeAttr('disabled');
			$('.cityall').attr('checked',false).removeAttr('disabled');
			$('.citycount').html('');
		}

		function selectAreas(){
			clearSelects();
			var old_citys = $('#areas').html().split(';');
			$('.city').each(function(){
				var parentcheck = false;
				for(var i in old_citys){
					if(old_citys[i]==$(this).attr('city')){
						parentcheck = true;
						$(this).get(0).checked = true;
						break;
					}
				}
				if(parentcheck){
					$(this).parent().parent().parent().parent().find('.cityall').get(0).checked=true;
				}
			});

			$("#modal-areas").modal();
			var citystrs = '';
			$('#btnSubmitArea').unbind('click').click(function(){
				$('.city:checked').each(function(){
					citystrs+= $(this).attr('city') +";";
				});
				$('#areas').html(citystrs);
				$("#selectedareas").val(citystrs);
			})
		}

		function renderCategoryThird(obj) {
			var index = obj.options[obj.selectedIndex].value;
			var html = "<option value='0'>请选择下级分类</option>";
			if (index == 0) {
				$("#ccate").html(html);
			}else {
				$.ajax({
					url: "/centre/category/getChildByPar",
					data:{"id":index},
					dataType: "json",
					success: function(data){
						for(var i=0; i< data.length; i++){
							html += '<option value="'+data[i].id+'">'+data[i].name+'</option>';
						}
						$("#ccate").html(html);
					}
				})
			}
		}

		function onSelectImgBtnClick(inputId, imgId) {
			layer.open({
				id:'selectImg',
				type : 2,
				title : '选择图片',
				maxmin : true,
				shadeClose : false,
				area : [ '60%', '70%' ],
				content : '/platform/config/selectImg/' + inputId +"/"+ imgId // iframe的url
			});
		}

		/**
		 * 加载图片URL
		 * @param inputId
		 * @param imgId
		 * @param url
		 */
		function loadImgUrl(inputId, imgId, url) {
			$('#'+inputId +'').val(url);
			$('#'+imgId +'').attr('src', url);
		}
	</script>
</body>
</html>
